/**
 * Created by oneminute on 7/17/14.
 */

var lz = require("../lib/utils/modules")();

exports.get = function (_req, _res, _opts, _callback) {
    var cid = _req.query.gid;
    var commodity = new lz.Commodity({id: cid});
    commodity.load({method: "byId"}, function (_err, _commodity) {
        var user = new lz.User({id: commodity.uid});
        if (_commodity) {
            user.load({method: "byId"}, function (_err, _user) {
                var obj = commodity.getInfo('f');
                obj.publisher = _user.name;
                obj.telephone = _user.phone;
                obj.position = _user.address;
                obj.lat = _user.lat;
                obj.lon = _user.lon;
                _callback(null, null, obj);

            });
        } else {
            lz.Logger.warn("/goods: 用户请求的商品不存在。");
            _callback(lz.Config.errors.getError(lz.Config.errors.REQUEST_NO_COMMODITY));
        }
    });
};